<?php
define('ROOT_PATH', dirname(__FILE__));
require_once ROOT_PATH . '/lib/dao/DMLFunctions.php';
header("Cache-Control:no-cache");
header("Pragma:no-cache");
header("Content-Type:text/html;charset=utf-8");
session_start();
//$id = intval($id);
if (isset($_GET['val'])) {
	$val = htmlspecialchars(strtoupper($_GET['val']));
}
/*if (empty($val)){
	exit();
}*/
$db = new DMLFunctions();
$action = $_GET['action'];
switch ($action) {
	case "argclass_year" :
		$year = intval($_GET['year']);
		$month = intval($_GET['month']);
		$day = intval($_GET['day']);
		$workgroup = intval($_GET['wg']);
		$group = intval($_GET['group']);
		$selsql = "select id from hs_hr_argclass_year where c_year='$year' and c_month='$month' and c_day='$day' and workgroup='$workgroup' and c_group='$group'";
		$query = $db->executeQuery($selsql);
		$info = mysql_fetch_row($query);
		if(!$info[0]) {
			$exesql = "insert into hs_hr_argclass_year(c_year,c_month,c_day,workgroup,c_group,c_class) values('$year','$month','$day','$workgroup','$group','$val')";
		}else {
			$id = $info[0];
			if (empty($val)) {
				$exesql = "delete from hs_hr_argclass_year where id='$id'";
			}else {
				$exesql = "update hs_hr_argclass_year set c_class='$val' where c_year='$year' and c_month='$month' and c_day='$day' and workgroup='$workgroup' and c_group='$group'";
			}
		}
		$db->executeQuery($exesql);
		break;
		
	case "argclass_member" :
		$year = intval($_GET['year']);
		$uid = intval($_GET['uid']);
		$month = intval($_GET['month']);
		$day = intval($_GET['day']);
		$group = intval($_GET['group']);
		//$group_type = urldecode($_GET['group_type']);
		$gobject = intval($_GET['gobject']);
		$membersql = "select emp_firstname from hs_hr_employee where emp_number='$uid'";
		$mquery = $db->executeQuery($membersql);
		$minfo = mysql_fetch_row($mquery);
		$member_name = $minfo[0];
		
		$selsql = "select id,m_class from hs_hr_argclass_members where mbid='$uid' and m_year='$year' and m_month='$month'";
		$query = $db->executeQuery($selsql);
		$info = mysql_fetch_row($query);
		$classArr = array();
		if(!$info[1]) {
			$classArr[$day] = $val;
			$class = serialize($classArr);
			$exesql = "insert into hs_hr_argclass_members(mbid,member_name,group_object,m_group,m_year,m_month,m_class) values('$uid','$member_name','$gobject','$group','$year','$month','$class')";
		}else {
			$id = $info[0];
			$m_class = unserialize($info[1]);
			if(isset($m_class[$day])) $c_before = $m_class[$day];
			else $c_before = '';
			$m_class[$day] = $val;
			$class = serialize($m_class);
			$exesql = "update hs_hr_argclass_members set m_class='$class' where id='$id'";
		}
		$db->executeQuery($exesql);
		
		/* 写入排班调整表 2012/4/28 */
		if(!$c_before) $c_before = "";
		if($c_before){
			$adjsql = "insert into hs_hr_class_adjust(mbid,member_name,class_name,a_year,a_month,a_day,c_before,c_now,handler) values('$uid','$member_name','$group','$year','$month','$day','$c_before','$val','".$_SESSION['fname']."')";
			$db->executeQuery($adjsql);
		}
		break;
		
	case "checkArgRecord" :
		$year = intval($_GET['year']);
		$month = intval($_GET['month']);
		$return_str = '';
		$selsql = "select id from hs_hr_argclass_year where `c_year`='$year' and c_month='$month' and workgroup=1 limit 1";
		$query = $db->executeQuery($selsql);
		$info1 = mysql_fetch_row($query);
		if(isset($info1[0]) && $info1[0]>0) $return_str .= '车间班、';
		$selsql = "select id from hs_hr_argclass_year where `c_year`='$year' and c_month='$month' and workgroup=3 limit 1";
		$query = $db->executeQuery($selsql);
		$info3 = mysql_fetch_row($query);
		if(isset($info3[0]) && $info3[0]>0) $return_str .= '保安班、';
		$selsql = "select id from hs_hr_argclass_year where `c_year`='$year' and c_month='$month' and workgroup=4 limit 1";
		$query = $db->executeQuery($selsql);
		$info4 = mysql_fetch_row($query);
		if(isset($info4[0]) && $info4[0]>0) $return_str .= '厨房班、';
		$selsql = "select id from hs_hr_argclass_year where `c_year`='$year' and c_month='$month' and workgroup=2 limit 1";
		$query = $db->executeQuery($selsql);
		$info2 = mysql_fetch_row($query);
		if(isset($info2[0]) && $info2[0]>0) $return_str .= '行政班、';
		$return_str = rtrim($return_str,'、');
		if($return_str) print $return_str;
		else print 'no';
		break;
		
	case "check_batch_member":
		$year = intval($_GET['year']);
		$month = intval($_GET['month']);
		$selsql = "select id from hs_hr_argclass_members where `m_year`='$year' and m_month='$month' limit 1";
		$query = $db->executeQuery($selsql);
		$info = mysql_fetch_row($query);
		if(isset($info[0]) && $info[0]>0) print 'yes';
		else print 'no';
		break;
}

/*
//重新截入新的数据并输出
if($noreturn!=1){
$query1="select $action,$field2,$field from #@__".$table." where ".$field1."='".$dh."'";
$sql->setquery($query1);
$sql->execute();
while($row=$sql->getArray()){
//总数量
$allnumber+=$row['number'];
//总金额
$allmoney+=$row[0]*$row[1];
//当事记录金额值
if($row[2]==$id)
$thisval=$row[0]*$row[1];
}
print $thisval."|".$allnumber."|￥".number_format($allmoney,2,'.',',');
}
else{
print '&nbsp;';
}*/
?>